# _*_ coding: utf-8 _*_
# @Time : 2024-01-19 21:48
# @Author : wf

import json
import jsonpath
import urllib.request

obj = json.load(open('starbucks-menu.json', 'r+', encoding='utf-8'))

preview_list = jsonpath.jsonpath(obj, '$..preview')
print(len(preview_list))
# print(preview_list)

title_list: list[str] = jsonpath.jsonpath(obj, '$..title')
print(len(title_list))
# print(title_list)

for index in range(len(preview_list)):
    img_url = "https://www.starbucks.com.cn" + preview_list[index]
    file_name = './img-starbucks/' + title_list[index].replace('/', '-') + '.jpg'
    urllib.request.urlretrieve(img_url, file_name)
    # print(img_url)
    # print(file_name)

